package setting_dao

import (
	"fmt"
	"hft/Http/Models/dao"
	"hft/Http/Services/country_setting/setting_model"

	"gorm.io/gorm"
)

type Emoji struct{}

func (e *Emoji) TextShow(textShow string, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if textShow == "" {
			return db
		} else {
			return db.Where(fmt.Sprintf("%%%v%%", textShow))
		}
	}
}

func (e *Emoji) Order(db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Order("sort desc")
	}
}

func (e *Emoji) List(paginate *setting_model.EmojiSearch, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Scopes(e.TextShow(paginate.TextShow, db)).Scopes(e.Order(db)).Scopes(dao.Paginate(dao.Page(paginate.Page), db))
	}
}

var EmojiDao = new(Emoji)
